//
//  LDWebController.m
//  Gift
//
//  Created by 李迪 on 15/11/10.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "LDWebController.h"
#import "BaseHeader.h"
#import "LDSqlData.h"
@interface LDWebController ()<UIWebViewDelegate>

@property (nonatomic, retain)UIWebView *webView;
@property (nonatomic, retain)NSURLRequest *request;
@property (nonatomic, retain)UIView *blackView;
@property (nonatomic, retain)UIButton *heartButton;

@end

@implementation LDWebController

- (void)dealloc
{
    self.webView.delegate = nil;
    [self.webView release];
    [_blackView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [self.webView setDelegate:self];
    [self.webView setScalesPageToFit:YES];
    
    _request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", _str]]];
    [self.webView setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:self.webView];
    [self.webView loadRequest:_request];
    
    
    self.heartButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.heartButton setImage:[UIImage imageNamed:@"xin"] forState:UIControlStateNormal];
    self.heartButton.frame = CGRectMake(0, 0, 30, 30);
    [self.heartButton setImage:[UIImage imageNamed:@"xin-3"] forState:UIControlStateSelected];
    [self.heartButton addTarget:self action:@selector(handleButton:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc]initWithCustomView:self.heartButton];
    
    self.navigationItem.rightBarButtonItem = barButton;
    
    //搜藏查询
    NSMutableArray *arr = [[LDSqlData sharedDataBase] selectCollectWithTitle:self.model.title];
    if (arr.count != 0) {
        self.heartButton.selected = YES;
    } else {
        self.heartButton.selected = NO;// 空心
    }

}

- (void)handleButton:(UIButton *)seled{
    seled.selected =! seled.selected;
    if (seled.selected == YES) {
        [[LDSqlData sharedDataBase] insertCollect:self.model];
    }
    if (seled.selected == NO) {
        [[LDSqlData sharedDataBase] deleteCollectWithTitle:self.model.title];
    }
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
